package com.yjhh.scala

import scala.collection.mutable

/**
  *
  *
  * Created by hlantian on 2017/11/22.
  */
object HelloPattermMatch {

  def main(args: Array[String]): Unit = {
    getSalary("Scala")
    getSalary("Spark")
    getMatchType(12)
//    getMatchCollection(Array("Scala"))
//    getMatchCollection(Array("Scala", "Python"))
//    getMatchCollection(Array("Spark"))

    getBigDataType(ComputtationFramework("Spark", true))
    getBigDataType(StorageFramework("HDFS", true))

//    gatVale("Spark",Map("Spark" -> 6, "Hadoop" -> 11))
//    gatVale("Spark1",Map("Spark" -> 6, "Hadoop" -> 11))
  }

  /**
    * 字符串进行匹配
    *
    * @param name
    */
  def getSalary(name: String): Unit = {
    name match {
      case "Spark" => println("$15W/year")
      case "Hadoop" => println("$10W/year")
      case _ if name == "Scala" => println("$14W/year")
      case _ if name == "Mapreduce" => println("$14W/year")
      case _ => println("$8W/year")
    }
  }

  /**
    * 类型匹配
    *
    * @param msg
    */
  def getMatchType(msg: Any): Unit = {
    msg match {
      case i: Int => println("Integer")
      case s: String => println("String")
      case d: Double => println("Double")
      case array: Array[Int] => println("Array")
      case _ => println("unknown type")
    }
  }

  /**
    * 类型进行匹配
    *
    * @param msg
    */
  def getMatchCollection(msg: Array[String]): Unit = {
    msg match {
      case Array("Scala") => println("One element")
      case Array("Scala", "Java") => println("Two element")
      case Array("Spark", _*) => println("Many elements begins with Spark")
      case _ => println("Unkown type")
    }
  }

  /**
    * case class 类型匹配
    *
    * @param data
    */
  def getBigDataType(data: DataFrameWork): Unit = {
    data match {
      case ComputtationFramework(name, popular)
      => println("ComputtationFramework name:" + name + " popular:" + popular)
      case StorageFramework(name, popular)
      => println("StorageFramework name:" + name + " popular:" + popular)
      case _
      => println("Some other type")
    }
  }

  def gatVale(key: String, map: Map[String,Any]): Unit = {
    map.get(key) match {
      case Some(value) => println(value)
      case None => println("none value")
    }
  }

}

class DataFrameWork

case class ComputtationFramework(name: String, popular: Boolean) extends DataFrameWork

case class StorageFramework(name: String, popular: Boolean) extends DataFrameWork
